//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"

//SAGITTARIUS headers:
#include "sagittarius/mem/sysalloc.h"

//system headers:
#include <sys/types.h>
#include <sys/mman.h>
//#include <stdlib.h>
//#include <stdint.h>

#ifndef NULL
    //#define NULL
#endif

//aligned at page boundary
void* sg_sysalloc(size_t n_pgs) {
    void* r = mmap(NULL, n_pgs*SG_PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
    AN(r && "mmap failure");
    return r;
}

int sg_sysfree(void* p, size_t n_pgs) {
    //munmap does not check that the specified region is actually mapped
    return munmap(p, n_pgs*SG_PAGE_SIZE);
}